package com.heima.article.listen;

import com.heima.article.service.ApArticleService;
import com.heima.model.common.constants.message.PublishArticleConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
public class PublishArticleListener {
    @Autowired
    private ApArticleService apArticleService;
    @RabbitListener(queuesToDeclare = {@Queue(value = PublishArticleConstants.PUBLISH_ARTICLE_QUEUE)})
    public void ListenPublishArticle(String newsId){
        log.info("收到发布文章的请求，消息内容{},消息时间{}",newsId,LocalDateTime.now().toString());
        apArticleService.publishArticle(Integer.valueOf(newsId));
        log.info("文章发布成功");
    }
}